class Solution {
public:
    int sum_lr(int mid, vector<int>& nums){
 
        if(mid != 0 && mid != nums.size() - 1)
        {
            int left = mid - 1;
            int right = nums.size() - mid - 1;
            int sum_left = 0;
            int sum_right = 0;
            
            while(left >= 0)
            {
                int sum_left = nums[left] + sum_left;
                left --;
            }
            
            while(right < nums.size())
            {
                int sum_right = nums[right] + sum_right;
                right ++;
            }
            
            if(sum_left == sum_right)
                return 0;           
            else if(sum_left > sum_right)
                return -1;
            else return 1;
        }
        
        return -1;     
    }
    

    
    int pivotIndex(vector<int>& nums) {
        
        if(nums.empty())
            return -1;
        
        int low = 0;
        int heigh = nums.size() - 1;
        
        for(int i = 0; i < nums.size() - 1; i++)
        {
            int mid = (low + heigh) / 2;
            if(!sum_lr(mid, nums))
            {
                return nums[mid];
                
            }   
            else if(sum_lr(mid, nums) == 1)
            {
                low = mid;
            }
            else
            {
                heigh = mid;
            }
            
            return nums[low];
        }
        
        return -1;
    }
};

// To return the center index
// Center index means that the sum of the numbers on the left is equal to the right